/***************************************
 * 说明：本文件主要列举第5章文中所实现的例题
 * *************************************/
#include "main.h"

/****************************
 * 例子5.1：访问公有基类的成员
 * **************************/
void Student::get_value()
{
    cin >> num >> name >> sex;
}
void Student::display()
{
    cout << "num = " << num << " name = " << name << " sex =" <<sex << endl;
}
void Student1::get_value1()
{
    cin >> age >> addr;
}
void Student1::display1()
{
    cout << "age = " << age << " addr = " << addr << endl;
}
void example1()
{
    Student1 stu;
    stu.get_value();
    stu.get_value1();
    stu.display();
    stu.display1();
}
/****************************
 * 例子5.2：将上述继承改为私有继承
 * **************************/
void Student2::get_value2()
{
    get_value();
    cin >> age >> addr;
}
void Student2::display2()
{
    display();
    cout << "age = " << age << " addr = " << addr << endl;
}
void example2()
{
    Student2 stu;
    stu.get_value2();
    stu.display2();
}
/****************************
 * 例子5.3：访问受保护基类的成员
 * **************************/
void Student3::get_value3()
{
    get_value();
    cin >> age >> addr;
}
void Student3::display3()
{
    display();
    cout << "age = " << age << " addr = " << addr << endl;
}
void example3()
{
    Student3 stu;
    stu.get_value3();
    stu.display3();
}

/****************************
 * 例子5.5：定义简单派生类的构造函数
 * **************************/
void Student5::display()
{
    cout << "num = " << num << " name = " << name << " sex =" <<sex << endl;
    cout << "age = " << age << " addr = " << addr << endl;
}
void example5()
{
    Student5 stu1(1, "wang", 'm', 32, "chengdu");
    Student5 stu2(2, "yang", 'w', 32, "chengdu");
    stu1.display();
    stu2.display();
}
/*******************************
 * 例子5.6：包含子类的派生类对象
 * *****************************/
void Student6::display()
{
    cout << "num = " << num << " name = " << name << " sex =" <<sex << endl;
    cout << "age = " << age6 << " addr = " << addr6 << endl;
    display_monitor();
}
void Student6::display_monitor()
{
    monitor.display();
}
void example6()
{
    Student6 stu(1, "wang", 'm', 32, "chengdu");
    stu.display();
}
/************************************
 * 例子5.7：多级派生情况的派生类构造函数
 * **********************************/
void example7()
{
    Student8 stu(1, "wang", 'm', 32, 100);
    stu.show_all();
}
/********************************************************************
 * 例子5.8：声明一个教师类和一个学生类，用多重继承的方式声明一个在职研究生类
 * 教师类包含name,age,title，学生类包含name1,sex,score.定义派生类时给出初始化
 * 数据，然后输出这些数据
 * ******************************************************************/
void example8()
{
    Graduate gra("wang", 32, 's', 'm', 100);
    gra.show();
}
/********************************************************************
 * 例子5.9：在5.8的基础上，声明一个公共基类Person，Teacher和Student9继承
 * ******************************************************************/
void example9()
{
    Graduate gra("wang", 32, 's', 'm', 100);
    gra.show();
}

/***********************************************************
 * 例子5.10:声明一个Student10，再声明一个Graduate，并用基类对象
 * 指针引用派生类对象
 * **********************************************************/
void example10()
{
    Student10* stu = new Graduate1(32, "wang", 90, 89);
    stu->show();
}
int main()
{
    example10();
    return 0;
}